package com.cardbaobao.cardbabyclient.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.utils.ScreenUtil;

/**
 * Created by Jiangzx on 2017/9/5 17:25.
 * 收款前实名认证对话框
 */

public class DebitSuggestionDialog extends Dialog {
    public interface ClickedListener{
        void onEnsureClicked();
    }

    private ClickedListener listener;
    public void setClickedListener(ClickedListener listener){
        this.listener=listener;
    }

    private TextView tvTitle;
    private TextView tvMessage;
    private TextView tvCancel;
    private TextView tvEnsure;
    public DebitSuggestionDialog(@NonNull Context context) {
        super(context,R.style.dialog);
        setContentView(R.layout.dialog_debit_suggestion);
        tvTitle= (TextView) findViewById(R.id.tv_title);
        tvMessage= (TextView) findViewById(R.id.tv_message);
        tvCancel= (TextView) findViewById(R.id.tv_cancel);
        tvEnsure= (TextView) findViewById(R.id.tv_ensure);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        tvEnsure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if(listener!=null){
                    listener.onEnsureClicked();
                }
            }
        });
        Window window=getWindow();
        if(window!=null){
            //对话框宽度占屏幕4/5，对话框宽高比为600:490
            WindowManager.LayoutParams params=window.getAttributes();
            final int width= (int) (ScreenUtil.getScreenWidth()*0.8f);
            params.width=width;
            params.height=WindowManager.LayoutParams.WRAP_CONTENT;
            params.gravity= Gravity.CENTER;
            window.setAttributes(params);
        }
        setCanceledOnTouchOutside(false);
    }

    public void setTitleText(@NonNull CharSequence titleText){
        if(tvTitle!=null){
            tvTitle.setText(titleText);
        }
    }

    public void setMessageText(@NonNull CharSequence messageText){
        if(tvMessage!=null){
            tvMessage.setText(messageText);
        }
    }

    public void setTvCancelText(@NonNull CharSequence cancelText){
        if(tvCancel!=null){
            tvCancel.setText(cancelText);
        }
    }

    public void setTvEnsureText(@NonNull CharSequence ensureText){
        if(tvEnsure!=null){
            tvEnsure.setText(ensureText);
        }
    }
}
